From 46431dff7447958cec5154a85461378d10708d6c Mon Sep 17 00:00:00 2001 From: robertl Date: Wed, 16 Oct 2002 05:41:51 +0000 Subject: [PATCH] Sketch in Groundspeak GPX fields. With this in place, the icon types on my magellan now show up differently for virtuals and physicals. Also, fix problem with magellan serial protocol on windows. --- gpsbabel/defs.h | 22 ++++++++++++++++++ gpsbabel/gpx.c | 54 ++++++++++++++++++++++++++++++++++++++++++++- gpsbabel/magproto.c | 36 +++++++++++++++++++++++++----- 3 files changed, 105 insertions(+), 7 deletions(-) diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index c3870be73..7c8484d99 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -64,6 +64,26 @@ typedef struct { altitude altitude; } position; +/* + * Extended data if waypoint happens to represent a geocache. This is + * totally voluntary data... + */ + +typedef enum { + gt_unknown = 0 , + gt_traditional, + gt_multi, + gt_virtual, + gt_letterbox, + gt_event, + gt_suprise +} geocache_type; + +typedef struct { + geocache_type type; + int diff; /* (multiplied by ten internally) */ + int terr; /* (likewise) */ +} geocache_data ; /* * This is a waypoint, as stored in the GPSR. It tries to not @@ -80,6 +100,7 @@ typedef struct { char *url_link_text; const char *icon_descr; time_t creation_time; + geocache_data gc_data; } waypoint; typedef void (*ff_init) (char const *); @@ -149,3 +170,4 @@ void le_write32(void *pp, unsigned i); * but that's not very nice for the folks near sea level. */ #define unknown_alt -99999999.0 + diff --git a/gpsbabel/gpx.c b/gpsbabel/gpx.c index 7ef7c9695..4e3b8cf93 100644 --- a/gpsbabel/gpx.c +++ b/gpsbabel/gpx.c @@ -29,6 +29,9 @@ static int in_name; static int in_time; static int in_desc; static int in_cdata; +static int in_gs_type; +static int in_gs_diff; +static int in_gs_terr; static char *cdatastr; static XML_Parser psr; @@ -98,12 +101,42 @@ gpx_start(void *data, const char *el, const char **attr) tag_wpt(attr); } if (strcmp(el, "time") == 0) { in_time++; + } if (strcmp(el, "groundspeak:type") == 0) { + in_gs_type++; + } if (strcmp(el, "groundspeak:difficulty") == 0) { + in_gs_diff++; + } if (strcmp(el, "groundspeak:terrain") == 0) { + in_gs_terr++; } } +struct +gs_type_mapping{ + geocache_type type; + const char *name; +} gs_type_map[] = { + { gt_traditional, "Traditional cache" }, + { gt_virtual, "Virtual cache" } +}; +static +geocache_type +gs_mktype(char *t) +{ + int i; + int sz = sizeof(gs_type_map) / sizeof(gs_type_map[0]); + + for (i = 0; i < sz; i++) { + if (0 == strcmp(t, gs_type_map[i].name)) { + return gs_type_map[i].type; + } + } + return gt_unknown; +} + static void gpx_end(void *data, const char *el) { + float x; if (in_cdata) { if (in_name && in_wpt) { wpt_tmp->shortname = xstrdup(cdatastr); @@ -129,6 +162,17 @@ gpx_end(void *data, const char *el) tm.tm_isdst = 1; wpt_tmp->creation_time = mktime(&tm); } + if (in_wpt && in_gs_type) { + wpt_tmp->gc_data.type = gs_mktype(cdatastr); + } + if (in_wpt && in_gs_diff) { + sscanf(cdatastr, "%f", &x); + wpt_tmp->gc_data.diff = x * 10; + } + if (in_wpt && in_gs_terr) { + sscanf(cdatastr, "%f", &x); + wpt_tmp->gc_data.terr = x * 10; + } in_cdata--; memset(cdatastr, 0, MY_CBUF); } @@ -147,6 +191,12 @@ gpx_end(void *data, const char *el) in_ele--; } else if (strcmp(el, "time") == 0) { in_time--; + } if (strcmp(el, "groundspeak:type") == 0) { + in_gs_type--; + } if (strcmp(el, "groundspeak:difficulty") == 0) { + in_gs_diff--; + } if (strcmp(el, "groundspeak:terrain") == 0) { + in_gs_terr--; } } @@ -160,8 +210,10 @@ gpx_cdata(void *dta, const XML_Char *s, int len) * horrible state just I can concatenate buffers that it hands * me as a cdata that are fragmented becuae they span a read. Grrr. */ - if ((in_name && in_wpt) || (in_desc && in_wpt) || (in_ele) || + (in_wpt && in_gs_type) || + (in_wpt && in_gs_diff) || + (in_wpt && in_gs_terr) || (in_time && (in_wpt || in_rte))) { estr = cdatastr + strlen(cdatastr); memcpy(estr, s, len); diff --git a/gpsbabel/magproto.c b/gpsbabel/magproto.c index 60bd44ac4..83272a2a2 100644 --- a/gpsbabel/magproto.c +++ b/gpsbabel/magproto.c @@ -1,4 +1,4 @@ -/* + /* Communicate Thales/Magellan serial protocol. Copyright (C) 2002 Robert Lipe, robertlipe@usa.net @@ -53,7 +53,6 @@ static mag_rxstate magrxstate; static int mag_error; static int last_rx_csum; static int found_done; -static icon_mapping_t *icon_mapping; static int got_version; static int is_file = 0; @@ -129,6 +128,8 @@ static icon_mapping_t map330_icon_table[] = { { "an", "winery" }, { "ao", "wreck" }, { "ap", "zoo" }, + { "ah", "Virtual cache"}, + { "an", "Event"}, { NULL, NULL } }; @@ -142,6 +143,7 @@ pid_to_model_t pid_to_model[] = { mm_unknown, 0, NULL } }; +static icon_mapping_t *icon_mapping = map330_icon_table; /* @@ -375,7 +377,6 @@ if (debug_serial) found_done = 1; return; } - mag_writeack(isum); } @@ -396,7 +397,14 @@ terminit(const char *portname) OPEN_EXISTING, 0, NULL); if (comport == INVALID_HANDLE_VALUE) { - fatal(MYNAME ": '%s'", portname); + char *buf; + + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL,GetLastError(),0, + (LPTSTR) &buf,0,NULL); + fatal(MYNAME ": '%s' cannot be opened. %s", portname, buf); } tio.DCBlength = sizeof(DCB); GetCommState (comport, &tio); @@ -445,12 +453,13 @@ termread(char *ibuf, int size) ibuf[i]='a'; for(;i < size;i++) { - if (ReadFile (comport, &ibuf[i], 1, &cnt, NULL) != TRUE) + if (ReadFile (comport, &ibuf[i], 1, &cnt, NULL) != TRUE) break; if (ibuf[i] == '\n') break; } ibuf[i] = 0; return ibuf; + } static void @@ -462,7 +471,6 @@ termwrite(char *obuf, int size) fwrite(obuf, size, 1, magfile_out); return; } - WriteFile (comport, obuf, size, &len, NULL); if (len != size) { fatal(MYNAME ":. Wrote %d of %d bytes.", len, size); @@ -587,6 +595,11 @@ mag_wr_init(const char *portname) mag_cleanse = m330_cleanse; got_version = 1; } else { + /* + * This is a serial device. The line has to be open for + * reading and writing, so we let rd_init do the dirty work. + */ + fclose(magfile_out); mag_rd_init(portname); } } @@ -799,6 +812,12 @@ mag_waypt_pr(const waypoint *waypointp) lat = (lat_deg * 100.0 + lat); icon_token = mag_find_token_from_descr(waypointp->icon_descr); + switch (waypointp->gc_data.type) { + case gt_virtual: + icon_token = mag_find_token_from_descr("Virtual cache"); + break; + + } owpt = global_opts.synthesize_shortnames ? mkshort(waypointp->description) : waypointp->shortname, odesc = waypointp->description ? waypointp->description : ""; @@ -830,9 +849,14 @@ mag_write(void) { if (!is_file) { mag_readmsg(); +#if !__WIN32__ + /* + * I have no idea why this is fatal under Windows. + */ mag_readmsg(); mag_readmsg(); mag_readmsg(); +#endif } /* * Whitespace is actually legal, but since waypoint name length is -- 2.30.2